import {Menu} from 'electron'
import {winURL} from '../setting'

let _mainWindow = null
const menuTemplate = [
    {
        label: '文件'
    },
    {
        label: '设置',
        submenu: [
            {
                label: '账号',
                click: function () {
                    goto('/account')
                }
            }
        ]
    },
    {
        //添加快捷键
        accelerator: 'F1',
        label: '帮助',
        click() {
            goto('/help')
        }
    }
]

function goto(url) {
    console.log(url)
    console.log(_mainWindow)
    if (_mainWindow)
        _mainWindow.loadURL(winURL + `/#${url}`)
}

export const initMenu = (mainWindow) => {

    _mainWindow = mainWindow
    const appMenu = Menu.buildFromTemplate(menuTemplate)
    Menu.setApplicationMenu(appMenu)
}
